package flex.cc.single.controller;

import com.alibaba.fastjson.JSONObject;
import flex.cc.core.support.BaseController;
import flex.cc.single.dto.vo.SingleOrderVo;
import flex.cc.single.service.AppointmentService;
import flex.cc.store.dto.entity.StoreCouponEntity;
import flex.cc.store.service.StoreCouponService;
import flex.cc.wrapper.WrapMapper;
import flex.cc.wrapper.Wrapper;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author wkangle
 * @className SingleDrivingController
 * @description 单项代驾Controller
 * @time 2022-04-06 22:05:57
 */
@SuppressWarnings("restriction")
@RestController
@RequestMapping(value = "/vehicleSvr/singleService/wechat")
public class SingleDrivingController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(SingleDrivingController.class);

    @Autowired
    private AppointmentService appointmentService;
    @Autowired
    private StoreCouponService storeCouponService;

    @PostMapping(value = "/drivingSave")
    @ApiOperation(httpMethod = "POST", value = "预约代驾提交")
    public Wrapper<JSONObject> drivingSave(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("DriveServiceController -- drivingSave() ====> {}", reqVo);
        JSONObject drivingSave = appointmentService.createDriverAppointment(reqVo);
        System.out.println(drivingSave);
        return WrapMapper.ok(drivingSave);
    }

    @PostMapping(value = "/driving/expired/info")
    @ApiOperation(httpMethod = "POST", value = "单项代驾卡券过期页面信息")
    public Wrapper<StoreCouponEntity> DrivingExpiredInfo(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("SingleDrivingController -- DrivingExpiredInfo() ====> {}", reqVo);
        StoreCouponEntity storeCouponEntity = storeCouponService.getOneByParams(reqVo);
        return WrapMapper.ok(storeCouponEntity);
    }

    @PostMapping(value = "/queryDrivingAddress")
    @ApiOperation(httpMethod = "POST", value = "根据用户输入的地址查询对应的坐标，用于搜索门店列表")
    public Wrapper<Map<String, Object>> queryDrivingAddress(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("SingleStoreController -- queryDrivingAddress() ====> {}", reqVo);
        Map<String, Object> queryDrivingAddress = appointmentService.queryDrivingAddress(reqVo);
        return WrapMapper.ok(queryDrivingAddress);
    }

    @PostMapping(value = "/drivingProgress")
    @ApiOperation(httpMethod = "POST", value = "代驾服务进展")
    public Wrapper<SingleOrderVo> drivingProgress(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("SingleDrivingController -- drivingProgress() ====> {}", reqVo);
        SingleOrderVo singleOrderVo = appointmentService.drivingProgress(reqVo);
        System.out.println(singleOrderVo.getCarNo());
        return WrapMapper.ok(singleOrderVo);
    }

    @PostMapping(value = "/drivingCancel")
    @ApiOperation(httpMethod = "POST", value = "取消代驾")
    public Wrapper<Map<String, String>> drivingCancel(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, String> reqVo) {
        logger.info("DriveServiceController -- drivingCancel() ====> {}", reqVo);
        Map<String, String> drivingCancel = appointmentService.driverCancel(reqVo);
        return WrapMapper.ok(drivingCancel);
    }

}
